package mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * @author 宋鑫宇
 * @version 1.0
 * 学习使用java语言连接数据库并执行sql语句
 */
public class JDBC_ {
    public static void main(String[] args) throws Exception {
        //注册驱动,jdk5之后可以不用写这行
//        Class.forName("com.mysql.jdbc.Driver");
        //2.获取数据库连接
        String url = "jdbc:mysql://127.0.0.1:3306/db1";
        String username = "root";
        String password = "root";
        Connection coon = DriverManager.getConnection(url,username,password);
        //3.定义sql语句
        String sql = "update stu set score = 250.0 where id = 5";
        //4.获取执行sql的对象
        Statement sta = coon.createStatement();
        //5.执行sql
        sta.execute(sql);

        //6.处理结果
        System.out.println("sql执行成功");

        //7.释放资源
        coon.close();
        sta.close();
    }
}
